home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Magnum One
/
Magnum One (Mid-American Digital) (Disc Manufacturing).iso
/
d14
/
atre12.arc
/
LF.ARC
/
SYNAN.C
< prev
next >
Wrap
C/C++ Source or Header
|
1991-07-27
|
39KB
|
1,350 lines
/* A Bison parser, made from synan.y */
#define FUNCTION 3
#define DOMAIN 4
#define DIMENSIONS 5
#define EQUALS 6
#define INTEGER 7
#define QUANTIZATION 8
#define COLON 9
#define TRAINING 10
#define SET 11
#define SIZE 12
#define TEST 13
#define CODING 14
#define LARGEST 15
#define SMALLEST 16
#define REAL 17
#define TREE 18
#define MIN 19
#define MAX 20
#define CORRECT 21
#define EPOCHS 22
#define VOTE 23
#define IDENTIFIER 24
#line 1 "synan.y"
/*****************************************************************************
**** ****
**** synan.y ****
**** ****
**** Copyright (C) A. Dwelly and W.W. Armstrong, 1990. ****
**** ****
**** All rights reserved. ****
**** ****
**** This is the syntax analyser for the small language `lf` that learns ****
**** a function using the atree package. Atree is an adaptive ****
**** logic network package based on work done by Prof. W. W. Armstrong ****
**** and others in the Department of Computing Science, University of ****
**** Alberta, and previous work at the Universite de Montreal, and at ****
**** AT&T Bell Laboratories, Holmdel, N. J. The software demonstrates ****
**** that networks consisting of many layers of linear threshold ****
**** elements can indeed be effectively trained. ****
**** ****
**** License: ****
**** A royalty-free license is granted for the use of this software for ****
**** NON-COMMERCIAL PURPOSES ONLY. The software may be copied and ****
**** modified provided this notice appears in its entirety and unchanged ****
**** in all copies, whether changed or not. Persons modifying the code ****
**** are requested to state the date, the changes made and who made them ****
**** in the modification history. ****
**** ****
**** Warranty: ****
**** No warranty of any kind is provided with this software. ****
**** This software is not supported. Neither the authors, nor the ****
**** University of Alberta, its officers, agents, servants or employees ****
**** shall be liable or responsible in any way for any damage to ****
**** property or direct personal or consequential injury of any nature ****
**** whatsoever that may be suffered or sustained by any licensee, user ****
**** or any other party as a consequence of the use or disposition of ****
**** this software. ****
**** ****
**** Patent: ****
**** The use of a digital circuit which transmits a signal indicating ****
**** heuristic responsibility is protected by U. S. Patent 3,934,231 ****
**** and others assigned to Dendronic Decisions Limited of Edmonton, ****
**** W. W. Armstrong, President. ****
**** ****
**** A royalty-free license is granted for the use of this patent to ****
**** run this software for NON-COMMERCIAL PURPOSES ONLY and the ****
**** extension of this patent license to modified versions of this ****
**** software is granted provided the purpose is NON-COMMERCIAL ONLY. ****
**** ****
**** Modification history: ****
**** ****
**** 09.02.90 Initial implementation, A.Dwelly ****
**** 91.04.15 Port to PC and minor bug fixes, R. Manderscheid ****
**** 91.05.20 Port to Windows, M. Thomas ****
**** ****
*****************************************************************************/
#include <stdio.h>
#include <stdlib.h>
#include <ctype.h>
#include <windows.h>
#include "atree.h"
#include "lf.h"
/* front end for MessageBox */
#define Printf(str,fmt) { \
char szBuff[80]; \
wsprintf(szBuff, str, fmt); \
MessageBox(NULL, szBuff, "LF Error", MB_OK | \
MB_ICONSTOP); \
}
int line_no;
int in_int;
float in_real;
int tuple_ptr;
int table_ptr;
int tmp_max_sz;
int table_size;
float **tmp_table;
bool train_size_flag;
bool test_size_flag;
bool largest_flag;
bool smallest_flag;
extern prog_type prog;
#ifndef YYLTYPE
typedef
struct yyltype
{
int timestamp;
int first_line;
int first_column;
int last_line;
int last_column;
char *text;
}
yyltype;
#define YYLTYPE yyltype
#endif
#ifndef YYSTYPE
#define YYSTYPE int
#endif
#include <stdio.h>
#ifndef __STDC__
#define const
#endif
#define YYFINAL 96
#define YYFLAG -32768
#define YYNTBASE 25
#define YYTRANSLATE(x) (x)
static const short yyrline[] = { 0,
100, 101, 104, 106, 155, 156, 158, 159, 160, 161,
162, 163, 164, 165, 168, 173, 187, 192, 199, 204,
218, 222, 227, 231, 237, 244, 266, 280, 287, 313,
328, 343, 360, 361, 367, 373, 387, 392, 399, 405,
419, 424, 430, 432, 433, 435, 436, 437, 438, 441,
447, 453, 459
};
static const char * const yytname[] = { 0,
"error","$illegal.","FUNCTION","DOMAIN","DIMENSIONS","EQUALS","INTEGER","QUANTIZATION","COLON","TRAINING",
"SET","SIZE","TEST","CODING","LARGEST","SMALLEST","REAL","TREE","MIN","MAX",
"CORRECT","EPOCHS","VOTE","IDENTIFIER","program"
};
static const short yyr1[] = { 0,
25, 25, 26, 27, 28, 28, 29, 29, 29, 29,
29, 29, 29, 29, 31, 30, 32, 32, 34, 33,
36, 35, 37, 35, 38, 40, 39, 41, 43, 42,
44, 44, 45, 45, 47, 46, 48, 48, 50, 49,
51, 51, 52, 53, 53, 54, 54, 54, 54, 55,
56, 57, 58
};
static const short yyr2[] = { 0,
2, 2, 3, 4, 1, 2, 1, 1, 1, 1,
1, 1, 1, 1, 0, 4, 1, 2, 0, 4,
0, 4, 0, 5, 5, 0, 5, 5, 0, 5,
1, 2, 1, 1, 0, 4, 1, 2, 0, 4,
1, 2, 2, 1, 2, 1, 1, 1, 1, 3,
4, 4, 3
};
static const short yydefact[] = { 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
43, 44, 46, 47, 48, 49, 1, 2, 0, 0,
0, 0, 0, 0, 0, 3, 5, 7, 8, 9,
10, 11, 12, 13, 14, 0, 0, 0, 0, 45,
0, 15, 0, 0, 19, 35, 39, 6, 50, 0,
0, 53, 4, 0, 26, 0, 29, 0, 0, 0,
0, 51, 52, 17, 16, 0, 0, 0, 0, 21,
20, 34, 33, 37, 36, 41, 40, 18, 27, 31,
25, 30, 28, 0, 23, 38, 42, 32, 0, 0,
22, 0, 24, 0, 0, 0
};
static const short yydefgoto[] = { 94,
3, 6, 26, 27, 28, 54, 65, 29, 59, 71,
84, 90, 30, 31, 66, 32, 33, 68, 79, 80,
34, 60, 75, 35, 61, 77, 4, 11, 12, 13,
14, 15, 16
};
static const short yypact[] = { 0,
2, -10, -11, 5, 7, 13, 10, 4, -2, 25,
-10,-32768,-32768,-32768,-32768,-32768,-32768,-32768, 26, 27,
23, 24, 30, 31, 32, 13,-32768,-32768,-32768,-32768,
-32768,-32768,-32768,-32768,-32768, 33, 35, 36, 37,-32768,
38,-32768, -1, 18,-32768,-32768,-32768,-32768,-32768, 39,
40,-32768,-32768, 41,-32768, 43,-32768, 44, 45, -3,
-3,-32768,-32768,-32768, 46, -3, 47, -3, 48,-32768,
49,-32768,-32768,-32768, -3,-32768, -3,-32768, -3,-32768,
-32768, -3,-32768, 34,-32768,-32768,-32768,-32768, 50, 42,
-32768, 51,-32768, 59, 60,-32768
};
static const short yypgoto[] = {-32768,
57,-32768,-32768, 52,-32768,-32768,-32768,-32768,-32768,-32768,
-32768,-32768,-32768,-32768,-32768,-32768,-32768,-32768, -29, -60,
-32768,-32768,-32768,-32768,-32768,-32768, 61,-32768, 54,-32768,
-32768,-32768,-32768
};
#define YYLAST 78
static const short yytable[] = { 74,
76, 7, 1, 72, 55, 5, 2, 1, 8, 9,
56, 19, 10, 73, 86, 36, 87, 2, 88, 38,
20, 88, 21, 57, 37, 22, 23, 24, 25, 58,
39, 41, 42, 43, 44, 45, 46, 47, 82, 49,
50, 51, 89, 52, 53, 62, 63, 64, 67, 69,
92, 70, 78, 81, 83, 85, 91, 93, 95, 96,
18, 0, 0, 17, 40, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 48
};
static const short yycheck[] = { 60,
61, 12, 3, 7, 6, 4, 18, 3, 19, 20,
12, 5, 23, 17, 75, 6, 77, 18, 79, 22,
8, 82, 10, 6, 21, 13, 14, 15, 16, 12,
6, 6, 6, 11, 11, 6, 6, 6, 68, 7,
6, 6, 9, 7, 7, 7, 7, 7, 6, 6,
9, 7, 7, 7, 7, 7, 7, 7, 0, 0,
4, -1, -1, 3, 11, -1, -1, -1, -1, -1,
-1, -1, -1, -1, -1, -1, -1, 26
};
#define YYPURE 1
/* -*-C-*- Note some compilers choke on comments on `#line' lines. */
#line 3 "bison.simple"
/* Skeleton output parser for bison,
Copyright (C) 1984 Bob Corbett and Richard Stallman
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 1, or (at your option)
any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */
#if (!defined (__STDC__) && defined (sparc)) || defined (__sparc__)
#include <alloca.h>
#endif
/* This is the parser code that is written into each bison parser
when the %semantic_parser declaration is not specified in the grammar.
It was written by Richard Stallman by simplifying the hairy parser
used when %semantic_parser is specified. */
/* Note: there must be only one dollar sign in this file.
It is replaced by the list of actions, each action
as one case of the switch. */
#define yyerrok (yyerrstatus = 0)
#define yyclearin (yychar = YYEMPTY)
#define YYEMPTY -2
#define YYEOF 0
#define YYFAIL goto yyerrlab;
#define YYACCEPT return(0)
#define YYABORT return(1)
#define YYERROR goto yyerrlab
#define YYTERROR 1
#ifndef YYIMPURE
#define YYLEX yylex()
#endif
#ifndef YYPURE
#define YYLEX yylex(&yylval, &yylloc)
#endif
/* If nonreentrant, generate the variables here */
#ifndef YYIMPURE
int yychar; /* the lookahead symbol */
YYSTYPE yylval; /* the semantic value of the */
/* lookahead symbol */
YYLTYPE yylloc; /* location data for the lookahead */
/* symbol */
int yynerrs; /* number of parse errors so far */
#endif /* YYIMPURE */
#if YYDEBUG != 0
int yydebug; /* nonzero means print parse trace */
/* Since this is uninitialized, it does not stop multiple parsers
from coexisting. */
#endif
/* YYMAXDEPTH indicates the initial size of the parser's stacks */
#ifndef YYMAXDEPTH
#define YYMAXDEPTH 200
#endif
/* YYMAXLIMIT is the maximum size the stacks can grow to
(effective only if the built-in stack extension method is used). */
#ifndef YYMAXLIMIT
#define YYMAXLIMIT 10000
#endif
#line 175 "bison.simple"
int
yyparse()
{
register int yystate;
register int yyn;
register short *yyssp;
register YYSTYPE *yyvsp;
YYLTYPE *yylsp;
int yyerrstatus; /* number of tokens to shift before error messages enabled */
int yychar1; /* lookahead token as an internal (translated) token number */
short yyssa[YYMAXDEPTH]; /* the state stack */
YYSTYPE yyvsa[YYMAXDEPTH]; /* the semantic value stack */
YYLTYPE yylsa[YYMAXDEPTH]; /* the location stack */
short *yyss = yyssa; /* refer to the stacks thru separate pointers */
YYSTYPE *yyvs = yyvsa; /* to allow yyoverflow to reallocate them elsewhere */
YYLTYPE *yyls = yylsa;
int yymaxdepth = YYMAXDEPTH;
#ifndef YYPURE
int yychar;
YYSTYPE yylval;
YYLTYPE yylloc;
int yynerrs;
#endif
YYSTYPE yyval; /* the variable used to return */
/* semantic values from the action */
/* routines */
int yylen;
#if YYDEBUG != 0
if (yydebug)
fprintf(stderr, "Starting parse\n");
#endif
yystate = 0;
yyerrstatus = 0;
yynerrs = 0;
yychar = YYEMPTY; /* Cause a token to be read. */
/* Initialize stack pointers.
Waste one element of value and location stack
so that they stay on the same level as the state stack. */
yyssp = yyss - 1;
yyvsp = yyvs;
yylsp = yyls;
/* Push a new state, which is found in yystate . */
/* In all cases, when you get here, the value and location stacks
have just been pushed. so pushing a state here evens the stacks. */
yynewstate:
*++yyssp = yystate;
if (yyssp >= yyss + yymaxdepth - 1)
{
/* Give user a chance to reallocate the stack */
/* Use copies of these so that the &'s don't force the real ones into memory. */
YYSTYPE *yyvs1 = yyvs;
YYLTYPE *yyls1 = yyls;
short *yyss1 = yyss;
/* Get the current used size of the three stacks, in elements. */
int size = yyssp - yyss + 1;
#ifdef yyoverflow
/* Each stack pointer address is followed by the size of
the data in use in that stack, in bytes. */
yyoverflow("parser stack overflow",
&yyss1, size * sizeof (*yyssp),
&yyvs1, size * sizeof (*yyvsp),
&yyls1, size * sizeof (*yylsp),
&yymaxdepth);
yyss = yyss1; yyvs = yyvs1; yyls = yyls1;
#else /* no yyoverflow */
/* Extend the stack our own way. */
if (yymaxdepth >= YYMAXLIMIT)
yyerror("parser stack overflow");
yymaxdepth *= 2;
if (yymaxdepth > YYMAXLIMIT)
yymaxdepth = YYMAXLIMIT;
yyss = (short *) alloca (yymaxdepth * sizeof (*yyssp));
bcopy ((char *)yyss1, (char *)yyss, size * sizeof (*yyssp));
yyvs = (YYSTYPE *) alloca (yymaxdepth * sizeof (*yyvsp));
bcopy ((char *)yyvs1, (char *)yyvs, size * sizeof (*yyvsp));
#ifdef YYLSP_NEEDED
yyls = (YYLTYPE *) alloca (yymaxdepth * sizeof (*yylsp));
bcopy ((char *)yyls1, (char *)yyls, size * sizeof (*yylsp));
#endif
#endif /* no yyoverflow */
yyssp = yyss + size - 1;
yyvsp = yyvs + size - 1;
#ifdef YYLSP_NEEDED
yylsp = yyls + size - 1;
#endif
#if YYDEBUG != 0
if (yydebug)
fprintf(stderr, "Stack size increased to %d\n", yymaxdepth);
#endif
if (yyssp >= yyss + yymaxdepth - 1)
YYABORT;
}
#if YYDEBUG != 0
if (yydebug)
fprintf(stderr, "Entering state %d\n", yystate);
#endif
/* Do appropriate processing given the current state. */
/* Read a lookahead token if we need one and don't already have one. */
yyresume:
/* First try to decide what to do without reference to lookahead token. */
yyn = yypact[yystate];
if (yyn == YYFLAG)
goto yydefault;
/* Not known => get a lookahead token if don't already have one. */
/* yychar is either YYEMPTY or YYEOF
or a valid token in external form. */
if (yychar == YYEMPTY)
{
#if YYDEBUG != 0
if (yydebug)
fprintf(stderr, "Reading a token: ");
#endif
yychar = YYLEX;
}
/* Convert token to internal form (in yychar1) for indexing tables with */
if (yychar <= 0) /* This means end of input. */
{
yychar1 = 0;
yychar = YYEOF; /* Don't call YYLEX any more */
#if YYDEBUG != 0
if (yydebug)
fprintf(stderr, "Now at end of input.\n");
#endif
}
else
{
yychar1 = YYTRANSLATE(yychar);
#if YYDEBUG != 0
if (yydebug)
fprintf(stderr, "Next token is %d (%s)\n", yychar, yytname[yychar1]);
#endif
}
yyn += yychar1;
if (yyn < 0 || yyn > YYLAST || yycheck[yyn] != yychar1)
goto yydefault;
yyn = yytable[yyn];
/* yyn is what to do for this token type in this state.
Negative => reduce, -yyn is rule number.
Positive => shift, yyn is new state.
New state is final state => don't bother to shift,
just return success.
0, or most negative number => error. */
if (yyn < 0)
{
if (yyn == YYFLAG)
goto yyerrlab;
yyn = -yyn;
goto yyreduce;
}
else if (yyn == 0)
goto yyerrlab;
if (yyn == YYFINAL)
YYACCEPT;
/* Shift the lookahead token. */
#if YYDEBUG != 0
if (yydebug)
fprintf(stderr, "Shifting token %d (%s), ", yychar, yytname[yychar1]);
#endif
/* Discard the token being shifted unless it is eof. */
if (yychar != YYEOF)
yychar = YYEMPTY;
*++yyvsp = yylval;
#ifdef YYLSP_NEEDED
*++yylsp = yylloc;
#endif
/* count tokens shifted since error; after three, turn off error status. */
if (yyerrstatus) yyerrstatus--;
yystate = yyn;
goto yynewstate;
/* Do the default action for the current state. */
yydefault:
yyn = yydefact[yystate];
if (yyn == 0)
goto yyerrlab;
/* Do a reduction. yyn is the number of a rule to reduce with. */
yyreduce:
yylen = yyr2[yyn];
yyval = yyvsp[1-yylen]; /* implement default value of the action */
#if YYDEBUG != 0
if (yydebug)
{
if (yylen == 1)
fprintf (stderr, "Reducing 1 value via line %d, ",
yyrline[yyn]);
else
fprintf (stderr, "Reducing %d values via line %d, ",
yylen, yyrline[yyn]);
}
#endif
switch (yyn) {
case 4:
#line 107 "synan.y"
{
/* Temporary */
in_int++;
prog.dimensions = in_int;
prog.quant = (int *) malloc((unsigned)sizeof(int) * in_int);
MEMCHECK(prog.quant);
prog.quant_step =
(float *)malloc((unsigned)sizeof(float) * in_int);
MEMCHECK(prog.quant_step);
prog.train_table =
(float **)malloc((unsigned)sizeof(float *) * in_int);
MEMCHECK(prog.train_table);
prog.test_table =
(float **)malloc((unsigned)sizeof(float *) * in_int);
MEMCHECK(prog.test_table);
prog.test_table_quant =
(int **)malloc((unsigned) sizeof(int *) * in_int);
MEMCHECK(prog.test_table_quant);
prog.largest =
(float *)malloc((unsigned)sizeof(float) * in_int);
MEMCHECK(prog.largest);
prog.smallest =
(float *)malloc((unsigned)sizeof(float) * in_int);
MEMCHECK(prog.smallest);
prog.string_width =
(int *)malloc((unsigned)sizeof(int) * in_int);
MEMCHECK(prog.string_width);
prog.walk_step = (int *)malloc((unsigned)sizeof(int) * in_int);
MEMCHECK(prog.walk_step);
prog.random_walk =
(bit_vec **)malloc((unsigned)sizeof(bit_vec *) * in_int);
MEMCHECK(prog.random_walk);
tmp_table = (float **)malloc((unsigned)sizeof(float *) * in_int);
MEMCHECK(tmp_table);
;
break;}
case 15:
#line 169 "synan.y"
{
tuple_ptr = 0;
;
break;}
case 16:
#line 173 "synan.y"
{
if (tuple_ptr > prog.dimensions)
{
prog.error = TRUE;
Printf("Semantics error : too many elements in quantization list on line %d\n", line_no);
}
if (tuple_ptr < prog.dimensions)
{
prog.error = TRUE;
Printf("Semantics error : not enough elements in quantization list on line %d\n", line_no);
}
;
break;}
case 17:
#line 188 "synan.y"
{
prog.quant[tuple_ptr] = in_int;
tuple_ptr++;
;
break;}
case 18:
#line 193 "synan.y"
{
prog.quant[tuple_ptr] = in_int;
tuple_ptr++;
;
break;}
case 19:
#line 200 "synan.y"
{
tuple_ptr = 0;
;
break;}
case 20:
#line 204 "synan.y"
{
if (tuple_ptr > prog.dimensions)
{
prog.error = TRUE;
Printf("Semantics error : too many elements in coding list on line %d\n", line_no);
}
if (tuple_ptr < prog.dimensions)
{
prog.error = TRUE;
Printf("Semantics error : not enough elements in coding list on line %d\n", line_no);
}
;
break;}
case 21:
#line 219 "synan.y"
{
prog.string_width[tuple_ptr] = in_int;
;
break;}
case 22:
#line 223 "synan.y"
{
prog.walk_step[tuple_ptr] = in_int;
tuple_ptr++;
;
break;}
case 23:
#line 228 "synan.y"
{
prog.string_width[tuple_ptr] = in_int;
;
break;}
case 24:
#line 232 "synan.y"
{
prog.walk_step[tuple_ptr] = in_int;
tuple_ptr++;
;
break;}
case 25:
#line 238 "synan.y"
{
prog.trainset_sz = in_int;
train_size_flag = TRUE;
;
break;}
case 26:
#line 245 "synan.y"
{
if (!train_size_flag)
{
Printf("Semantics error : training set defined before size\n",0);
return(-1);
}
else
{
int i;
tmp_max_sz = prog.trainset_sz;
tuple_ptr = 0;
table_ptr = 0;
for (i = 0; i < prog.dimensions; i++)
{
tmp_table[i] = (float *)malloc((unsigned)sizeof(float)*prog.trainset_sz);
MEMCHECK(tmp_table[i]);
}
}
;
break;}
case 27:
#line 266 "synan.y"
{
int i;
if (tuple_ptr < prog.trainset_sz)
{
prog.error = TRUE;
Printf("Semantics error : not enough elements in training set\n",0);
}
for (i = 0; i < prog.dimensions; i++)
{
prog.train_table[i] = tmp_table[i];
}
;
break;}
case 28:
#line 281 "synan.y"
{
prog.testset_sz = in_int;
test_size_flag = TRUE;
;
break;}
case 29:
#line 288 "synan.y"
{
if (!test_size_flag)
{
Printf("Semantics error : test set defined before size\n",0);
return(-1);
}
else
{
int i;
tmp_max_sz = prog.testset_sz;
tuple_ptr = 0;
table_ptr = 0;
for (i = 0; i < prog.dimensions; i++)
{
tmp_table[i] =
(float *)malloc((unsigned)sizeof(float) * prog.testset_sz);
MEMCHECK(tmp_table[i]);
prog.test_table_quant[i] =
(int *)malloc((unsigned) sizeof(int) * prog.testset_sz);
MEMCHECK(prog.test_table_quant[i]);
}
}
;
break;}
case 30:
#line 313 "synan.y"
{
int i;
if (tuple_ptr < prog.testset_sz)
{
prog.error = TRUE;
Printf("Semantics error : not enough elements in test set\n",0);
}
for (i = 0; i < prog.dimensions; i++)
{
prog.test_table[i] = tmp_table[i];
}
;
break;}
case 31:
#line 329 "synan.y"
{
tmp_table[table_ptr][tuple_ptr] = in_real;
table_ptr++;
if (table_ptr == prog.dimensions)
{
table_ptr = 0;
tuple_ptr++;
}
if (tuple_ptr > tmp_max_sz)
{
Printf("Semantics error: too many elements in table\n",0);
return(-1);
}
;
break;}
case 32:
#line 344 "synan.y"
{
tmp_table[table_ptr][tuple_ptr] = in_real;
table_ptr++;
if (table_ptr == prog.dimensions)
{
table_ptr = 0;
tuple_ptr++;
}
if (tuple_ptr > tmp_max_sz)
{
Printf("Semantics error: too many elements in table\n",0);
return(-1);
}
;
break;}
case 34:
#line 362 "synan.y"
{
in_real = (float) in_int;
;
break;}
case 35:
#line 368 "synan.y"
{
tuple_ptr = 0;
largest_flag = TRUE;
;
break;}
case 36:
#line 373 "synan.y"
{
if (tuple_ptr > prog.dimensions)
{
prog.error = TRUE;
Printf("Semantics error : too many elements in largest list on line %d\n", line_no);
}
if (tuple_ptr < prog.dimensions)
{
prog.error = TRUE;
Printf("Semantics error : not enough elements in largest list on line %d\n", line_no);
}
;
break;}
case 37:
#line 388 "synan.y"
{
prog.largest[tuple_ptr] = in_real;
tuple_ptr++;
;
break;}
case 38:
#line 393 "synan.y"
{
prog.largest[tuple_ptr] = in_real;
tuple_ptr++;
;
break;}
case 39:
#line 400 "synan.y"
{
tuple_ptr = 0;
smallest_flag = TRUE;
;
break;}
case 40:
#line 405 "synan.y"
{
if (tuple_ptr > prog.dimensions)
{
prog.error = TRUE;
Printf("Semantics error : too many elements in smallest list on line %d\n", line_no);
}
if (tuple_ptr < prog.dimensions)
{
prog.error = TRUE;
Printf("Semantics error : not enough elements in smallest list on line %d\n", line_no);
}
;
break;}
case 41:
#line 420 "synan.y"
{
prog.smallest[tuple_ptr] = in_real;
tuple_ptr++;
;
break;}
case 42:
#line 425 "synan.y"
{
prog.smallest[tuple_ptr] = in_real;
tuple_ptr++;
;
break;}
case 50:
#line 442 "synan.y"
{
prog.tree_sz = in_int;
;
break;}
case 51:
#line 448 "synan.y"
{
prog.max_correct = in_int;
;
break;}
case 52:
#line 454 "synan.y"
{
prog.max_epochs = in_int;
;
break;}
case 53:
#line 460 "synan.y"
{
if (in_int % 2 != 1)
{
Printf("Semantics error : vote number is even\n",0);
return(-1);
}
prog.vote = in_int;
;
break;}
}
/* the action file gets copied in in place of this dollarsign */
#line 412 "bison.simple"
yyvsp -= yylen;
yyssp -= yylen;
#ifdef YYLSP_NEEDED
yylsp -= yylen;
#endif
#if YYDEBUG != 0
if (yydebug)
{
short *ssp1 = yyss - 1;
fprintf (stderr, "state stack now");
while (ssp1 != yyssp)
fprintf (stderr, " %d", *++ssp1);
fprintf (stderr, "\n");
}
#endif
*++yyvsp = yyval;
#ifdef YYLSP_NEEDED
yylsp++;
if (yylen == 0)
{
yylsp->first_line = yylloc.first_line;
yylsp->first_column = yylloc.first_column;
yylsp->last_line = (yylsp-1)->last_line;
yylsp->last_column = (yylsp-1)->last_column;
yylsp->text = 0;
}
else
{
yylsp->last_line = (yylsp+yylen-1)->last_line;
yylsp->last_column = (yylsp+yylen-1)->last_column;
}
#endif
/* Now "shift" the result of the reduction.
Determine what state that goes to,
based on the state we popped back to
and the rule number reduced by. */
yyn = yyr1[yyn];
yystate = yypgoto[yyn - YYNTBASE] + *yyssp;
if (yystate >= 0 && yystate <= YYLAST && yycheck[yystate] == *yyssp)
yystate = yytable[yystate];
else
yystate = yydefgoto[yyn - YYNTBASE];
goto yynewstate;
yyerrlab: /* here on detecting error */
if (! yyerrstatus)
/* If not already recovering from an error, report this error. */
{
++yynerrs;
yyerror("parse error");
}
if (yyerrstatus == 3)
{
/* if just tried and failed to reuse lookahead token after an error, discard it. */
/* return failure if at end of input */
if (yychar == YYEOF)
YYABORT;
#if YYDEBUG != 0
if (yydebug)
fprintf(stderr, "Discarding token %d (%s).\n", yychar, yytname[yychar1]);
#endif
yychar = YYEMPTY;
}
/* Else will try to reuse lookahead token
after shifting the error token. */
yyerrstatus = 3; /* Each real token shifted decrements this */
goto yyerrhandle;
yyerrdefault: /* current state does not do anything special for the error token. */
#if 0
/* This is wrong; only states that explicitly want error tokens
should shift them. */
yyn = yydefact[yystate]; /* If its default is to accept any token, ok. Otherwise pop it.*/
if (yyn) goto yydefault;
#endif
yyerrpop: /* pop the current state because it cannot handle the error token */
if (yyssp == yyss) YYABORT;
yyvsp--;
yystate = *--yyssp;
#ifdef YYLSP_NEEDED
yylsp--;
#endif
#if YYDEBUG != 0
if (yydebug)
{
short *ssp1 = yyss - 1;
fprintf (stderr, "Error: state stack now");
while (ssp1 != yyssp)
fprintf (stderr, " %d", *++ssp1);
fprintf (stderr, "\n");
}
#endif
yyerrhandle:
yyn = yypact[yystate];
if (yyn == YYFLAG)
goto yyerrdefault;
yyn += YYTERROR;
if (yyn < 0 || yyn > YYLAST || yycheck[yyn] != YYTERROR)
goto yyerrdefault;
yyn = yytable[yyn];
if (yyn < 0)
{
if (yyn == YYFLAG)
goto yyerrpop;
yyn = -yyn;
goto yyreduce;
}
else if (yyn == 0)
goto yyerrpop;
if (yyn == YYFINAL)
YYACCEPT;
#if YYDEBUG != 0
if (yydebug)
fprintf(stderr, "Shifting error token, ");
#endif
*++yyvsp = yylval;
#ifdef YYLSP_NEEDED
*++yylsp = yylloc;
#endif
yystate = yyn;
goto yynewstate;
}
#line 469 "synan.y"
/* Lexical states */
#define LEX_START 0
#define LEX_INT 1
#define LEX_DEC 2
#define LEX_IDENT 3
#define LEX_PUNCT 4
#define LEX_COMMENT 5
#define LEX_STOP 1000
#define MAX_LEN_BUF 1000
int lexstate;
int nextchar;
FILE *yyin;
#define ISCOMMENT(c) (c == '#')
void
lexinit()
{
lexstate = LEX_START;
nextchar = getc(yyin);
}
isextdigit(c)
char c;
{
return((c == 'e') || (c == 'E') || (c == '+') || (c == '-') || isdigit(c));
}
iswhite(c)
char c;
{
if (c == '\n')
{
line_no++;
return(TRUE);
}
else
{
return((c == 0) || (c == ' ') || (c == '\t'));
}
}
gettoken(str)
char *str;
{
int i;
int outcode;
static struct tok
{
char *token;
int code;
} toktab[] =
{
"function" , FUNCTION,
"dimension" , DIMENSIONS,
"dimensions" , DIMENSIONS,
"=" , EQUALS,
"quantization", QUANTIZATION,
":" , COLON,
"coding" , CODING,
"training" , TRAINING,
"set" , SET,
"size" , SIZE,
"test" , TEST,
"tree" , TREE,
"minimum" , MIN,
"min" , MIN,
"maximum" , MAX,
"max" , MAX,
"correct" , CORRECT,
"epochs" , EPOCHS,
"largest" , LARGEST,
"smallest" , SMALLEST,
"domain" , DOMAIN,
"vote" , VOTE,
NULL ,0
};
outcode = IDENTIFIER;
for (i = 0; toktab[i].token != NULL; i++)
{
if (strcmp(str,toktab[i].token) == 0)
{
outcode = toktab[i].code;
break;
}
}
return(outcode);
}
int
yylex()
{
char yytext[MAX_LEN_BUF];
int bufptr;
bool found_token;
int token;
found_token = FALSE;
bufptr = 0;
while (!found_token)
{
switch (lexstate)
{
case LEX_START:
while (iswhite(nextchar))
{
nextchar = getc(yyin);
}
if (ISCOMMENT(nextchar))
{
nextchar = getc(yyin);
lexstate = LEX_COMMENT;
}
else if (isdigit(nextchar) || (nextchar == '-'))
{
yytext[bufptr++] = nextchar;
nextchar = getc(yyin);
lexstate = LEX_INT;
}
else if (isalpha(nextchar))
{
yytext[bufptr++] = nextchar;
nextchar = getc(yyin);
lexstate = LEX_IDENT;
}
else if (ispunct(nextchar))
{
yytext[bufptr++] = nextchar;
nextchar = getc(yyin);
lexstate = LEX_PUNCT;
}
else if (nextchar == EOF)
{
lexstate = LEX_STOP;
}
else
{
Printf("Lexical error: unrecognized character %d\n",(int) nextchar);
exit(0);
}
break;
case LEX_INT:
while (isdigit(nextchar))
{
yytext[bufptr++] = nextchar;
nextchar = getc(yyin);
}
if (nextchar == '.')
{
yytext[bufptr++] = nextchar;
nextchar = getc(yyin);
lexstate = LEX_DEC;
}
else
{
yytext[bufptr] = 0;
in_int = atoi(yytext);
token = INTEGER;
found_token = TRUE;
}
break;
case LEX_DEC:
while (isextdigit(nextchar))
{
yytext[bufptr++] = nextchar;
nextchar = getc(yyin);
}
yytext[bufptr] = 0;
sscanf(yytext,"%g",&in_real);
token = REAL;
found_token = TRUE;
break;
case LEX_IDENT:
while (isalpha(nextchar) || isdigit(nextchar))
{
yytext[bufptr++] = nextchar;
nextchar = getc(yyin);
}
yytext[bufptr] = 0;
token = gettoken(yytext);
found_token = TRUE;
break;
case LEX_PUNCT:
yytext[bufptr] = 0;
token = gettoken(yytext);
found_token = TRUE;
break;
case LEX_COMMENT:
while (nextchar != '\n')
{
nextchar = getc(yyin);
}
lexstate = LEX_START;
break;
case LEX_STOP:
token = 0;
found_token = TRUE;
break;
}
}
if (lexstate != LEX_STOP)
{
lexstate = LEX_START;
}
return(token);
}
yyerror(s)
char *s;
{
Printf("Error found on line %d\n",line_no);
prog.error = TRUE;
}